- if @import
  = hidden_field_tag :import, "true"
- attributes_scope = "activerecord.attributes.#{resource_class.name.underscore}"
- locales = Releaf.application.config.all_locales
- @translation_ids_to_destroy ||= []

- template_html = capture do
  %tr.item{ data: { name: :translations }, style: 'display:none' }
    %td.translation-name
      .wrap
        %input{type: "text", class: "text", name: "translations[][key]"}
    - locales.each_with_index do |locale, j|
      %td.translationCell{data: {locale: locale}}
        %input{type: "text", class: "text", name: "translations[][localizations][#{locale}]"}
    %td.delete-column.only-icon
      = releaf_button(nil, "times", class: %w(danger remove-nested-item), title: t("Remove", scope: controller_scope_name))
%section.nested{data: {name: "translations", releaf: {template: html_escape(template_html)}}}
  %table.table
    %thead
      %tr
        %th.code= t("key", scope: attributes_scope)
        - locales.each do |locale|
          %th{"data-locale" => locale}
            %span.name= builder.translate_locale(locale)
        %th.delete
    %tbody#variables.list
      - @collection.each_with_index do |translation, index|
        - @translation_ids_to_destroy << translation.id
        %tr.item{ id: "translation_#{translation.id}", data: { name: :translations, index: index } }
          %td.translation-name{title: translation.key}
            .wrap
              %input{type: "text", class: "text", name: "translations[][key]", value: translation.key }
          - locales.each_with_index do |locale, j|
            %td.translationCell{data: {locale: locale}}
              %input{type: "text", class: "text", name: "translations[][localizations][#{locale}]", value: translation.locale_value(locale) }
          %td.delete-column.only-icon
            = releaf_button(nil, "times", class: %w(danger remove-nested-item), title: t("Remove", scope: controller_scope_name))
  %div.tools
    = releaf_button(t('Add item', :scope => 'admin.releaf_translations'), "plus", class: "add-nested-item")
= hidden_field_tag :existing_translations, @translation_ids_to_destroy.join(",")
